package officeserver.main;

import officeserver.log_error.FileIOException;
import officeserver.office.Office;

public class CtrlC { 
	private volatile boolean keepOn = true; 
	public class RunWhenShuttingDown extends Thread 
	{ 
		public void run() 
		{ 
			System.out.println("Control-C caught. Shutting down..."); 
			keepOn = false; 
			try { Thread.sleep(2000); 
			} catch (InterruptedException e) 
			{
				e.printStackTrace();
			} 
		} 
	} 
	public void runProgram() throws InterruptedException, FileIOException 
	{ 
		Runtime.getRuntime().addShutdownHook(new RunWhenShuttingDown()); 
		while(keepOn) { 
			//System.out.println("running..."); Thread.sleep(1000); 
		} 
		System.out.println("Saving database."); 
		Office temp = new Office();
		temp.save();
		System.out.println("Database Saved"); 
		} 
}